package com.jmlee.component;

import com.jmlee.pojo.Admin;
import org.springframework.stereotype.Component;

/**
 * @Description TODO
 * @Author jmLee
 * @Date 2021/3/5 15:41
 * @Version 1.0
 */
@Component
public class HostHolder {

    ThreadLocal<Admin> admins = new ThreadLocal<>();

    public void setAdmin(Admin admin) {
        admins.set(admin);
    }

    public Admin getAdmin() {
        return admins.get();
    }

    // 手动清除，防止内存泄漏（弱引用 WeakReference）
    public void clear() {
        admins.remove();
    }
}
